//
//  LocationTableController.m
//  quickDoctor
//
//  Created by zhaowei on 17/3/8.
//  Copyright © 2017年 SWS. All rights reserved.
//

#import "LocationTableController.h"
#import "LocationMode.h"
#import <YYModel.h>
#import <MJExtension.h>
#import "CityTableViewController.h"
#define location @"location"
@interface LocationTableController ()
@property(nonatomic,assign)NSInteger row;

@end

@implementation LocationTableController {
    //省份数组
    NSArray *_provinceArr;
    
    //城市数组
    NSArray *_citiesArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    

    [self setupUI];
    
    [self loadData];
}


- (void)loadData{
//    _dataSource = [LocationMode mj_objectArrayWithFile:@"province.plist"];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"province.plist" ofType:nil];
    
    NSArray *dictArr = [NSArray arrayWithContentsOfFile:filePath];
    _provinceArr = dictArr;
    
    //遍历省份数组
    
    
    
    
}
/// 初始化页面
- (void)setupUI{
    //注册
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:location];
    
    self.title = @"选择当前省份位置";
    //隐藏返回按钮
    self.navigationItem.hidesBackButton = YES;
    
//    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home_nav_button_back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home_nav_button_back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    //设置左侧箭头颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    

}



/// pop操作
- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
    
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    
    return _provinceArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:location forIndexPath:indexPath];
    
    //通过row取出数组中的字典
    NSDictionary *dict = _provinceArr[indexPath.row];
    
    cell.textLabel.text = dict[@"name"];
    
    return cell;
}
//选中cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //通过点击cell,传递indexPath.row
    _row = indexPath.row;
    
    //创建控制器
    CityTableViewController *cityController = [[CityTableViewController alloc] init];
    //点击跳转
    [self.navigationController pushViewController:cityController animated:YES];
    
    cityController.rowIndex = _row;
    cityController.provinceArr = _provinceArr;
    cityController.name = _provinceArr[indexPath.row][@"name"];
}


@end
